import Vue from 'vue';
import VueRouter from 'vue-router';
import routes from './routes';
import {
  setTitle
} from '@/utils/index.js'
Vue.use(VueRouter);

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes,
});
const HAS_LOGIN = true;
router.beforeEach((to, from, next) => {
  console.log('beforeEach', to);
  if (to.meta && to.meta.title) setTitle(to.meta.title)

  if (to.name !== 'Login') {
    if (HAS_LOGIN) next()
    else next({ name: 'Login' })
  } else {
    if (HAS_LOGIN) next({ name: 'Home' })
    else next()
  }
})
//导航被确认
router.beforeResolve((to, from, next) => {
  console.log('异步路由被解析后');
  next()
})

router.afterEach((to, from) => {
  console.log('afterEach loading');

})

export default router;
